<template>
  <el-card>
    <el-row>
      <el-form :model="state" :inline="true">
        <el-form-item label="用户名称" prop="userName">
          <el-input v-model="state.userName" placeholder="请输入用户名称" clearable></el-input>
        </el-form-item>
        <el-form-item label="日志类型" prop="status">
          <el-select v-model="state.status" placeholder="请选择日志类型" clearable>
          <el-option value="1" label="成功"></el-option>
          <el-option value="2" label="失败"></el-option>
        </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="getLogs">查询</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-table :data="state.tableData" row-key="id" :border="true">
      <el-table-column label="访问编号" prop="loginId" width="200" align="center"></el-table-column>
      <el-table-column label="用户名称" prop="userName" width="150" align="center"></el-table-column>
      <el-table-column label="设备类型" prop="deviceType" width="150" align="center"></el-table-column>
      <el-table-column label="IP地址" prop="ipaddr" width="140" align="center"></el-table-column>
      <el-table-column label="登录地点" prop="loginLocation" show-overflow-tooltip width="200" align="center"></el-table-column>
      <el-table-column label="操作系统" prop="os" show-overflow-tooltip width="150" align="center"></el-table-column>
      <el-table-column label="浏览器" prop="browser" width="150" align="center"></el-table-column>
      <el-table-column label="登录状态" prop="status" width="100" align="center">
        <template #default="scope">
          <el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">{{scope.row.status === 1 ? '成功' : '失败'}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作说明" prop="description" show-overflow-tooltip width="150" align="center"></el-table-column>
      <el-table-column label="访问时间" prop="loginTime" width="180" align="center"></el-table-column>
    </el-table>
    <!--    分页-->
    <pagination v-model:current="state.current" v-model:size="state.size" v-model:total="state.total" @get-list="getLogs"></pagination>
  </el-card>
</template>

<script setup>
import {getLoginLogList} from "../../api/log/sysLog";
import {errorMsg} from "../../utils/message";
import Pagination from "../../components/Pagination";
import {onMounted, reactive, ref} from "vue";

const state = reactive({
  userName: '',
  msg: null,
  tableData: [],
  status: '',
  current: 1,
  size: 10,
  total: 0
})

onMounted(() => {
  getLogs()
})

const getLogs = () => {
  const params = {
    userName: state.userName,
    currentPage: state.current,
    size: state.size,
    status: state.status
  }
  getLoginLogList(params).then(res => {
    if (res.code == 200){
      state.tableData = res.data.records
      state.total = res.data.total
    } else {
      errorMsg(res.message)
    }
  })
}
</script>

<style scoped>
.el-tooltip__popper{
  margin-left: 20px;
}
</style>